package study.edumanagesystemspringboot.entity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zouran
 * createDate：2023/12/26  12:30
 */
public class Principal implements Visitor {
    @Override
    public Map<String, Object> visit(Student student) {
        List<Map<String, Object>> maps = student.getAllGrades();
        double sumCredit = 0.0;
        for (Map<String, Object> map : maps) {
            if ((double) map.get("score") >= 60)
                sumCredit += (double) map.get("credit");
        }
        Map<String, Object> map = new HashMap<>();
        map.put("identify", student.getIdentify());
        map.put("id", student.getId());
        map.put("name", student.getName());
        map.put("department", student.getDepartment());
        map.put("sumCredit", sumCredit);
        return map;
    }

    @Override
    public Map<String, Object> visit(Teacher teacher) {
        Map<String, Object> map = new HashMap<>();
        map.put("identify", teacher.getIdentify());
        map.put("id", teacher.getId());
        map.put("name", teacher.getName());
        map.put("department", teacher.getDepartment());
        map.put("satisfaction", teacher.getSatisfaction());
        map.put("title", teacher.getTitle());
        map.put("phone", teacher.getPhone());
        return map;
    }
}
